package com.pwt.service;

import com.pwt.common.ResultPage;
import com.pwt.entity.JobNo;
import com.pwt.model.ComboBoxModel;
import com.pwt.model.DataModel;
import com.pwt.repository.JobNoRepository;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * JobNo service层
 *
 * @author auto generated
 * @date 2022-01-20 09:40:38
 */
@Service
public class JobNoService {

    private JobNoRepository jobNoRepository;

    private JPAQueryFactory jpaQueryFactory;

    public JobNoService(JobNoRepository jobNoRepository, JPAQueryFactory jpaQueryFactory) {
        this.jobNoRepository = jobNoRepository;
        this.jpaQueryFactory = jpaQueryFactory;
    }

    /**
     * 分页查询 云之家消息发送配置
     * @param page 当前页
     * @param limit 每页展示数
     * @param type  1-控制限，2-上下限（公差限）
     * @param jobNumber  工作号
     * @return
     */
    public ResultPage<JobNo> queryJobNoPage(Integer page, Integer limit, Integer type, String jobNumber){
        return this.jobNoRepository.queryJobNoPage( page, limit, type, jobNumber);
    }

    /**
     * 新增修改 云之家消息发送配置
     * @param jobNo
     * @return
     */
    public JobNo updateJobNo(JobNo jobNo){
        JobNo jobNoByType = this.jobNoRepository.queryJobNoByType(jobNo.getType());
        if(jobNoByType != null){
            jobNoByType.setJobNos(jobNo.getJobNos());
            return this.jobNoRepository.save(jobNoByType);
        }else{
            return this.jobNoRepository.save(jobNo);
        }
    }

    /**
     * 查询所有用户工位号 下拉框
     * @return
     */
    public List<ComboBoxModel> queryUserJobNo(){
        return this.jobNoRepository.queryUserJobNo();
    }

}
